const WebSocket = require('ws');
const { wsf, wsfb } = require('./websocket_server.js')
const { findAvailablePort } = require('./AvailablePort.js')

const conf = {
    port: 11111,
    servers: {}
}

function websocketServer(server_name, callBack) {
    findAvailablePort(conf.port, port => {
        conf.port = port

        console.log(`\x1B[41m______________________\x1B[0m\n\x1B[42m______________________\x1B[0m\n\x1B[43m______________________\x1B[0m\n\x1B[44m______________________\x1B[0m\n\x1B[45m______________________\x1B[0m\n\x1B[46m______________________\x1B[0m\n\x1B[47m______________________\x1B[0m\n `)
        console.log(
            '\x1B[44m\x1b[37m\x1b[44m %s \x1b[0m%s',
            server_name.toUpperCase(),
            ` 端口 \x1B[36m${port}\x1B[0m 可用`
        )

        const wss = new WebSocket.Server({ port: port })

        conf.servers[server_name] = wss
        // 暂时用不到
        wsf[server_name] && wsf[server_name](wss)
        callBack && callBack(wss)
    })
}

websocketServer('图形情感')

/*  */
ret = {
    msg: {
        code: 0,
        data: ''
    }
}